/*Main Program Module*/

/*Required Header Files*/
#include <pic18.h>
#include "main.h"

/*Modules Header files*/
#include "timer.h"
#include "sched.h"

/*Methods declaration*/
void vTask1( stepType *step );
void vTask2( stepType *step );

/*Main Code*/
void main( void )
{
    /*Scheduler Init*/
    schedInit();

    /*Modules Initialization*/
    vTimerInit(10Mhz, 1000);
 
    /*Services Initialization*/
    schedTaskCreate(vTask1, 1);
    schedTaskCreate(vTask2, 2);

    /*Init semaphores*/
    schedEventInit(1,0); //Semaphore number, semaphore state (0= unsignaled)

    /*Interrups Initialization*/
    intEnablePriority(ON);
    intLowEnable(ON);
    intHighEnable(ON);
    
    /*Scheduler*/
    for ( ;; )
        {
            schedule();
        }
}

/*Interrupt Hook*/
void interrupt hiIntHook( void )
{
    if (CCP1IF) { vTimerISR(); }
}

void interrupt low_priority lowIntHook( void )
{
}

void vTask1( stepType *step )
{
    /*Example Task with a 100ms delay an a signaling of a semaphore*/
    schedSignalSem(1);
    schedDelay(100);


}

void vTask2( stepType *step )
{
    /*This tasks waits 1000ms for the semaphore 1 to get signaled*/
    schedWait(1000, 1);
}
